/**
 * 
 */
package com.wegax.finprod.processor.init;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;

import org.springframework.core.Ordered;
import org.springframework.web.WebApplicationInitializer;

/**
 * @author wegax
 * 
 */
public class ProcessorInitializer implements WebApplicationInitializer, Ordered, ServletContextListener {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.core.Ordered#getOrder()
	 */
	@Override
	public int getOrder() {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext)
	 */
	@Override
	public void onStartup(ServletContext container) throws ServletException {
		// FIXME (wegax) waits for Servlet API 3.0 on cloudfoundry.org
		// GlobalContext.initContext();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		GlobalContext.initContext();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 */
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		GlobalContext.destroyContext();
	}

}
